<template>
  <div class="clearfix">
    <a-upload :fileList="fileList" :remove="handleRemove" :beforeUpload="beforeUpload">
      <a-button>
        <a-icon type="upload"/>
        Select File
      </a-button>
    </a-upload>
    <a-button
      type="primary"
      @click="handleUpload"
      :disabled="fileList.length === 0"
      :loading="uploading"
      style="margin-top: 16px"
    >
      {{uploading ? 'Uploading' : 'Start Upload' }}
    </a-button>
  </div>
</template>

<script>
  import {axios} from '@/utils/request'

  export default {
    name: "App",
    components: {},
    mixins: [],
    data() {
      return {
        fileList: [],
        uploading: false,
        url: {
          fileUpload: window._CONFIG['domianURL'] + "/sys/common/upload",
        },
      }
    },
    created: {},
    mounted: {},
    computed(){
      const formData = new FormData();
      var cl={
        userId:"123"
      }
      var user={
        userXm:"123"
      }
      formData.append('cl', cl);
      formData.append('user',user);
      this.ww(formData);
      axios({
        method: 'get',
        url: 'http://127.0.0.1:8080/jeecg-boot/my/qz_dic/test',
        data: formData,
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      });
    },
    methods: {
      handleRemove(file) {
        console.log(file);
        const index = this.fileList.indexOf(file);
        const newFileList = this.fileList.slice();
        newFileList.splice(index, 1);
        this.fileList = newFileList;
      },
      beforeUpload(file) {
        console.log(file);
        var isAPK = file.type === "application/vnd.android.package-archive";
        var down100MB = file.size / 1024 / 1024 < 100;
        if (!isAPK) {
          this.$message.error('You can only upload APK file!');
        } else if (!down100MB) {
          this.$message.error('APK must smaller than 100MB!');
        } else {
          this.fileList = [];
          this.fileList = [...this.fileList, file];
        }
        return isAPK && down100MB;
      },
      handleUpload() {
        const formData = new FormData();
        formData.append('file', this.fileList[0]);
        formData.append('bbh',"1-0-0");
        this.uploading = true;
        this.uploadFileRequest(formData);
      },
      uploadFileRequest(formData) {
        axios({
          method: 'post',
          url: this.url.fileUpload,
          data: formData,
          headers: {
            'Content-Type': 'multipart/form-data'
          }
        });
        this.uploading = false;
      }
    },
    props: {},
    watch: {}
  }
</script>

<style scoped>

</style>